import { ref, reactive, onMounted, nextTick } from 'vue'
import { ExperiencePageApi } from '@/api/Experience/ExperienceList'
export default function tableModel() {
  const tableDate = reactive({
    search: {
      page: 1,
      size: 10,
      createId: ''
    },
    Loading: false,
    list: [] as any,
    total: 0,
    searchParams: {} as any,
    tableHeight: 400,
  })
  onMounted(() => {


    getExperiencePage()
    nextTick(() => {
      tableDate.tableHeight = window.innerHeight - 185
    })
  })
  const getExperiencePage = async () => {
    const userInfo = JSON.parse(sessionStorage.getItem('UserInfoList') as any)
    tableDate.search.createId = userInfo.id
    const res = await ExperiencePageApi({ ...tableDate.search, ...tableDate.searchParams })
    if (res.code === 200) {
      // console.log(res.data);
      tableDate.list = res.data.records
      tableDate.total = res.data.total
    }
  }
  const serachBtn = () => {
    tableDate.search.page = 1
    getExperiencePage()
  }
  const tableRowClassName = ({ row, rowIndex }) => {
    if (rowIndex % 2 === 1) {
      return "warning-row";
    } else {
      return "success-row";
    }
  }
  const resetBtn = () => {
    tableDate.search.page = 1
    tableDate.searchParams = {}
    getExperiencePage()
  }
  const handleSizeChange = (size) => {
    tableDate.search.size = size
    getExperiencePage()

  }
  const handleCurrentChange = (page) => {
    tableDate.search.page = page
    getExperiencePage()
  }
  const auditStatusMethod = (row, column, cellValue, index) => {
    return cellValue == '0' ? '未审核' : cellValue == '1' ? '审核成功' : '审核驳回'
  }
  return {
    tableDate, serachBtn, resetBtn, getExperiencePage, handleSizeChange, handleCurrentChange, auditStatusMethod,tableRowClassName
  }
}